package liming.ai.core;

import liming.ai.data.AbstractRequest;

public interface ResponseInterface {
    ResponseInterface DefaultResponseInterface = new ResponseInterface() {
        boolean isReasoning = false;

        @Override
        public void oneReasoningContent(String reasoningContent) {
            if (!isReasoning) {
                isReasoning = true;
                System.out.print("\n[思考] ");
            }
            System.out.print(reasoningContent);
        }

        @Override
        public void oneContent(String content) {
            if (isReasoning) {
                isReasoning = false;
                System.out.print("\n[结果] " + content);
            } else
                System.out.print(content);
        }

        public void onComplete(String reasoningContent,String content) {
            System.out.println("\n最终思考:\n " + reasoningContent);
            System.out.println("\n最终结果:\n " + content);
        }

        public void onError(AbstractRequest request, String error) {
            System.out.println("\n[ERROR] \t" + error);
        }

    };

    /**
     * 输出一次思考内容
     *
     * @param reasoningContent 思考内容
     */
    default void oneReasoningContent(String reasoningContent) {
        DefaultResponseInterface.oneReasoningContent(reasoningContent);
    }

    /**
     * 输出一次回答内容
     *
     * @param content 内容
     */
    default void oneContent(String content) {
        DefaultResponseInterface.oneContent(content);
    }

    /**
     * 输出最终内容
     *
     * @param reasoningContent 思考内容
     * @param content 回答内容
     */
    default void onComplete(String reasoningContent,String content) {
        DefaultResponseInterface.onComplete(reasoningContent,content);
    }

    /**
     * 输出错误信息
     *
     * @param request 请求
     * @param error 错误信息
     */
    default void onError(AbstractRequest request, String error) {
        DefaultResponseInterface.onError(request,error);
    }
}
